package main

import "fmt"

/**
  闭包
*/

func addUpper() func(a int) int {
	var base = 0
	fmt.Println("未进入匿名函数前的值：", base)
	return func(a int) int {
		base += a
		fmt.Println("当前闭包中变量base的值：", base)
		return base
	}
}

func main() {
	myFun1 := addUpper()
	fmt.Println(myFun1(1))
	fmt.Println(myFun1(3))
	fmt.Println(myFun1(2))
	myFun2 := addUpper()
	fmt.Println(myFun2(1))
	fmt.Println(myFun2(1))
	fmt.Println(myFun2(1))
}
